<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<div class="login-container">
  <h2>登录</h2>
  <form action="login.php" method="POST">
    <input type="email" name="email" placeholder="邮箱" required>
    <input type="password" name="password" placeholder="密码" required>
    <button type="submit">登录</button>
  </form>
  <p>没有账号？<a href="register.html">注册一个！</a></p>
</div>

</body>
</html>
<script type="module">
    let auth; // 提升作用域

    // 初始化代码
    const initAuth = () => {
        const firebaseConfig = {/* 保持配置一致 */};
        const app = initializeApp(firebaseConfig);
        auth = getAuth(app);
        window.__auth = auth; // 暴露到全局
    }

    initAuth();

    window.login = async () => {
        try {
            const userCredential = await signInWithEmailAndPassword(auth, email, password);
            console.log('跳转前用户状态:', auth.currentUser);
            window.location.href = 'profile.html';
        } catch (error) {
            console.error('完整错误堆栈:', error);
        }
    }
</script>